/*--------------------------------------------------------------------------
 *  sabinos.Log , version 0.1
 *  (c) 2008 Felipe Sabino
 *
 *  http://www.sabinos.net
 *  sabinosfelipe@gmail.com
 *
 * This code is under GNU General Public License (GPL) http://www.gnu.org/licenses/gpl-3.0.txt
 *
 *--------------------------------------------------------------------------*/

if(Object.isUndefined(sabinos) || sabinos == null)
    var sabinos = {}; //defines 'sabinos' 'namespace'

if(Object.isUndefined(sabinos.Log) || sabinos.Log == null)
{
    sabinos.Log = Class.create();
    sabinos.Log.AppenderCollection = Class.create();

    sabinos.Log.AppenderMisingException = 'sabinos.Log.Appenders Exception - Missing sabinos.Log.Appenders namespace. Probably Appenders file was not properly loaded';

    sabinos.Log.Level = new Hash();
    sabinos.Log.Level.All = 63;
    sabinos.Log.Level.Trace = 1;
    sabinos.Log.Level.Debug = 2;
    sabinos.Log.Level.Info = 4;
    sabinos.Log.Level.Warn = 8;
    sabinos.Log.Level.Error = 16;
    sabinos.Log.Level.Fatal = 32;
    
    //Keeps a boolean indication whether logging is enabled.
    sabinos.Log.Enabled = false;

    sabinos.Log.prototype = {
        initialize: function(caller, appenders) {
            this.Caller = caller;                                           //Saves the page name
            this.Appenders = new sabinos.Log.AppenderCollection(appenders);      //Creates the Appender Collection Object
            this.Enabled = true;
        },
        trace : function(message, objects){
            this.log(sabinos.Log.Level.Trace, message, objects);
        },
        debug : function(message, objects){
            this.log(sabinos.Log.Level.Debug, message, objects);
        },
        info : function(message, objects){
            this.log(sabinos.Log.Level.Info, message, objects);
        },
        warn : function(message, objects){
            this.log(sabinos.Log.Level.Warn, message, objects);
        },
        error : function(message, objects){
            this.log(sabinos.Log.Level.Error, message, objects);
        },
        fatal : function(message, objects){
            this.log(sabinos.Log.Level.Fatal, message, objects);
        },
        log : function(level, message, objects) {
            if(sabinos.Log.Enabled && this.Enabled)
                this.Appenders.log(level, this, message, objects);
        }

    }
    
    //This class is overriden when appender file is loaded
    sabinos.Log.AppenderCollection.prototype = {
        initialize : Prototype.emptyFunction,
        add : Prototype.emptyFunction,
        log : Prototype.emptyFunction,
        loadConfigurationFile : Prototype.emptyFunction
    }
}